/*
 * @Author: 一路向阳 tt_sunzhenfeng@163.com
 * @Date: 2024-02-22 22:03:45
 * @LastEditors: 一路向阳 tt_sunzhenfeng@163.com
 * @LastEditTime: 2024-02-22 22:21:25
 * @FilePath: \utils_ts\25.keyof和in.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
export {};

interface Person {
  name: string;
  age: number;
  [key: number]: number | string;
  [key: string]: number | string;
}

// keyof 后面一般跟接口  表示接口的这些属性名之一(实际上就是： 前面的这些)
type Ptype = keyof Person; // "name" | "age" | number | string 都是常量
let p1: Ptype;
p1 = 'name';
p1 = 'age';
p1 = 1;
p1 = '123';

// interface PerItf {
//   [idx: string]: number | string;
// }
// let p2: PerItf = {
//   aa: 1
// }

type StrOrNum = string | number;
type PItf = {
  [key in StrOrNum]: string;
}

let obj: PItf = {
  a: '',
  10: ''
}

// typeof 提取变量或者对象的类型
let str = '123';
type StrType = typeof str; // string
let aaa: StrType = 'xx';

let obj2 = {
  name: 1,
  age: '',
  height: 10
}
type OType = typeof obj2;
let obj3: OType = {
  name: 123,
  age: '123',
  height: 123
}

